﻿using System;
using System.Data;
using System.Collections.Generic;

using VIT.Web.UI;
using VIT.Web.Controls;
using VIT.Library;

namespace VIT.Web.Admin
{
    public partial class ChangePassword : VITComponent
    {
        Provider.Account acc;
        protected void Page_Load(object sender, EventArgs e)
        {
            acc = new Provider.Account();
            acc.UserName = Session["userName"].ToString();
            if (!IsPostBack) LoadData(); 
        }

        #region Methods
        private void LoadData()
        {
            acc.GetSingle();
            if (acc.UserName != "")
            {
                UserName.Text = acc.UserName;
                UserName.ReadOnly = true;
            }
        }

        private bool SaveData()
        {
            acc.UserName = UserName.Text;
            acc.Password = Password.Text.EnCodeMD5();
            return acc.ChangePassword();
        }

        private void setTrueVisible(System.Web.UI.HtmlControls.HtmlGenericControl control)
        {
            lblThanhCong.Visible = false;
            lblThatBai.Visible = false;

            control.Visible = true;
        }
        #endregion

        #region Events
        protected void Save_Click(object sender, EventArgs e)
        {
            if (SaveData()) setTrueVisible(lblThanhCong);
            else setTrueVisible(lblThatBai);
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            RedirectComponent("Account", "AccountList");
        }
        #endregion
    }
}